package com.jxlst.channel.pro.service.impl;

import com.jxlst.channel.pro.constant.ConfigDict;
import com.jxlst.channel.pro.pojo.Result;
import com.jxlst.channel.pro.pojo.dto.MemberReqDto;
import com.jxlst.channel.pro.service.MemberService;
import com.jxlst.channel.pro.util.ExceptionUtils;
import com.jxlst.channel.pro.util.HttpUtil;
import com.jxlst.channel.pro.util.RequestUtil;
import com.jxlst.channel.pro.util.verifyUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.SortedMap;

/**
 * 商户进件业务实现
 * <p>
 * 1.
 * </p>
 *
 * @author : wukong
 * @version : 1.0.0
 * @date : 2018/7/18
 */
@Slf4j
@Service
public class MemberServiceImpl implements MemberService {
    @Autowired
    private HttpUtil httpUtil;

    @Override
    public Result member(MemberReqDto reqDto) {
        Result result;
        log.info("商户进件，请求:{}", reqDto);
        try {
            SortedMap<String, String> parameters = RequestUtil.packageParams(reqDto);
            String post = httpUtil.post(ConfigDict.MEMBER_URL, RequestUtil.packageReq(parameters));
            verifyUtil.getSuccessResult(post, null);
            result = new Result();
            log.info("商户进件，响应:{}", reqDto);
        } catch (Exception e) {
            result = ExceptionUtils.getResponse(e);
            log.error("商户进件", e);
        }
        log.info("商户进件，响应:{}", result);
        return result;
    }
}
